class Agent {
  position: number[];
  velocity: number[];
  radius: number;

  constructor(position: number[], velocity: number[], radius: number) {
    this.position = position;
    this.velocity = velocity;
    this.radius = radius;
  }
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
class ORCA {
  agents: Agent[];
  timeHorizon: number;

  constructor(agents: Agent[], timeHorizon: number) {
    this.agents = agents;
    this.timeHorizon = timeHorizon;
  }

  computePreferredVelocities(): void {
    for (let i = 0; i < this.agents.length; i++) {
      const agent = this.agents[i];
      // 这里可以定义每个代理的期望速度
      agent.velocity = [1, 0]; // 示例：向右移动
    }
  }

  updateAgentVelocities(): void {
    for (let i = 0; i < this.agents.length; i++) {
      const agent = this.agents[i];
      const orcaVelocities = this.computeORCAVelocities(agent, i);
      // 选择一个合适的速度
      agent.velocity = orcaVelocities[0]; // 示例：选择第一个可行速度
    }
  }

  computeORCAVelocities(agent: Agent, index: number): number[][] {
    const velocities: number[][] = [];

    for (let j = 0; j < this.agents.length; j++) {
      if (j === index) continue;

      const other = this.agents[j];
      const relativePosition = [other.position[0] - agent.position[0], other.position[1] - agent.position[1]];
      // const relativeVelocity = [agent.velocity[0] - other.velocity[0], agent.velocity[1] - other.velocity[1]];

      const distSq = relativePosition[0] ** 2 + relativePosition[1] ** 2;
      const combinedRadius = agent.radius + other.radius;

      if (distSq < combinedRadius ** 2) {
        // 处理碰撞
        // 计算可行的速度
        // 这里可以加入具体的避碰逻辑
      }
    }

    // 返回计算出的可行速度
    return velocities;
  }

  run(): void {
    this.computePreferredVelocities();
    this.updateAgentVelocities();
  }
}

// 示例用法
// const agents = [new Agent([0, 0], [0, 0], 0.5), new Agent([1, 1], [0, 0], 0.5)];

// const orca = new ORCA(agents, 2.0);
// orca.run();

// console.log(agents);
